﻿using System.Threading.Tasks;
using K9Nano.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace K9Nano.IdentityServerCore.Account
{
    [ApiController]
    [AllowAnonymous]
    [Route("account/[action]")]
    public abstract class AccountController<TUser, TService> : ControllerBase
        where TUser : User
        where TService : AccountAppService<TUser>
    {
        protected readonly TService AccountAppService;

        protected AccountController(TService accountAppService)
        {
            AccountAppService = accountAppService;
        }

        [HttpPost]
        public virtual IActionResult Register()
        {
            return Ok();
        }

        [HttpGet]
        public virtual async Task<UserInfoDto> UserInfo()
        {
            if (User.Identity.IsAuthenticated)
            {
                return await AccountAppService.GetUserInfo();
            }

            return new UserInfoDto
            {
                Name = "游客"
            };
        }
    }
}